import {createReducer} from '../utils/index';
import { USER_LOGIN_SUCCESS, USER_LOGIN_FAILURE ,LOGIN_USER_REQUEST} from '../contants/index';


const initialState = {
    session:{},
    isAuthenticated: null,
    statusText: null,
    authName:{},
};
export default createReducer(initialState, {
    [LOGIN_USER_REQUEST]: (state, payload) => {
        return Object.assign({}, state, {
            'statusText': null
        });
    },
    [USER_LOGIN_SUCCESS]: (state, payload) => {
        console.log(payload);
        return Object.assign({}, state, {
            'isAuthenticated': true,
            'session': payload.session,
            'statusText': 'You have been successfully logged in.',
            'authName':payload.authName,
        });

    },
    [USER_LOGIN_FAILURE]: (state, payload) => {
        return Object.assign({}, state, {
            'isAuthenticated': false,
            'session': null,
            'statusText': `Authentication Error: ${payload.errCode} ${payload.errContent}`
        });
    },     
});